#include "ProductTestMic.h"

#define DEF_TAG             "TutkMic"

extern Com_u8 g_ProductTest_Media_Running;
extern Com_s32 g_ProductTest_ThreadNum;

Com_pvoid Ext_ProductTest_Mic_Thread(Com_pvoid arg)
{
    Com_s32 ret;
    pStSdkRingBufInfoProducer pro;
    pStSdkRingBufInfo ring_buff;
    StSdkAudioInfo info;

    memset(&info,0,sizeof(info));

    pro = (pStSdkRingBufInfoProducer)arg;
    ring_buff = &pro->mic_ring_buffer;

    ret = Ext_SdkMic_Init();
    if(ret != DEF_COM_SUCCESS)
    {
        PRT_ERR(DEF_TAG,"mic init failed !\n");
        return NULL;
    }

    PRT_NORMAL("start mic !!\n");

    g_ProductTest_ThreadNum++;

    while(g_ProductTest_Media_Running)
    {
        ret = Ext_SdkMediaCom_GetMicData(&info);
        if (ret != DEF_COM_SUCCESS)
        {
            continue;
        }

        StSdkRingBufFrame frame;

        memset(&frame, 0, sizeof(StSdkRingBufFrame));

        frame.frame_buf = (Com_ps8)info.buf;
        frame.frame_len = info.size;
        frame.frame_type = 0;

        pro->push_audio_frame_to_ring_buffer(ring_buff,&frame);

        Ext_SdkMediaCom_ReleaseMicData();
    }

    ret = Ext_SdkMic_Exit();
    if(ret != DEF_COM_SUCCESS)
    {
        PRT_ERR(DEF_TAG,"mic exit failed !\n");
        return NULL;
    }

    g_ProductTest_ThreadNum--;
    pthread_exit(0);
}
